
<template>
	<view class="shoppingCart-core">
		<view class="shoppingCart-core-shopname">
			<image src="../../pages/static/icon_home_egg@2x.png" class="shoppingCart-core-logo"></image>
			<view class="shoppingCart-core-name">阿帝蔬菜店</view>
		</view>
		<view class="shoppingCart-core-shop">
			<view class="shoppingCart-core-shopsheet">
				<image src="../../pages/static/icon_home_vegetable@2x.png" class="shoppingCart-core-logo"></image>
			</view>
			<view class="shoppingCart-core-right">
				<view class="shoppingCart-core-productname">上海青250g/半斤</view>
				<view class="shoppingCart-core-bottom">
					<image src="../../pages/static/icon_reduce_number@2x.png" class="shoppingCart-core-img"></image>
					<view class="shoppingCart-core-number">10</view>
					<image src="../../pages/static/icon_add_number@2x.png" class="shoppingCart-core-img"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			flag: true,
			cartCount: 0
		};
	},
	props: {
		///组件类型 0用户搜索 1终端商城  2终端购物车 3 用户购物车  4确认订单  5用户商城  6终端搜索
		type: {
			type: Number,
			default: 0
		},

		index: {
			type: Number,
			default: 0
		},

		//终端号
		terminalNo: {
			type: String,
			default: ''
		},

		//终端名称
		terminalName: {
			type: String,
			default: ''
		},

		//终端距离
		distance: {
			type: Number,
			default: 0
		},

		//终端图片
		terminalPicture: {
			type: String,
			default: ''
		},

		//月销量
		monthlySaleNum: {
			type: Number,
			default: 0
		},

		//商品id
		goodsId: {
			type: Number,
			default: null
		},

		//标签
		tags: {
			type: String,
			default: ''
		},
		//名称
		name: {
			type: String,
			default: ''
		},
		//库存
		stock: {
			type: Number,
			default: null
		},
		//缩略图
		thumbUrl: {
			type: String,
			default: ''
		},
		//类型
		drugType: {
			type: Number | String,
			default: ''
		},
		//规格
		spec: {
			type: String,
			default: ''
		},

		//价格
		salePrice: {
			type: Number,
			default: 0
		},
		//购物车数量
		cartNum: {
			type: Number,
			default: 0
		}
	},

	watch: {
		cartNum: {
			handler(value) {
				this.cartCount = value ? value : 0;
			},
			immediate: true
		}
	},
	computed: {
		tagsList() {
			return this.tags.split(',');
		}
	},
	created() {
		uni.createSelectorQuery()
			.in(this)
			.selectAll('.skeleton-rect-radius')
			.boundingClientRect()
			.exec(rects => {
				uni.$emit('skeletonComponents', rects[0]);
			});

	},

	methods: {
		// gotoGoodsInfo() {
			
		// 	if(this.type!=4){
		// 		console.log(this.type)
		// 		uni.navigateTo({
		// 			url: '/pages-terminal/goods/goodsInfo?goodsId=' + this.goodsId + '&terminalNo=' + this.terminalNo
		// 		});
		// 	}
			
		// },

		// gotoTerminal() {
		// 	uni.navigateTo({
		// 		url: '/pages-terminal/terminal/terminal?terminalNo=' + this.terminalNo
		// 	});
		// },

		//增减购物车商品数量，返回该商品在购物车中数量
		// addOrSubShoppingCart(num) {
			//增加库存判断缓解服务器压力
			// if (this.type == 1 && num > 0 && this.cartCount >= this.stock) {
			// 	uni.showToast({
			// 		title: '库存不足',
			// 		icon: 'none'
			// 	});
			// 	return;
			// }

			// if (this.flag) {
			// 	this.flag = false;
			// 	this.$api
			// 		.addOrSubShoppingCart({
			// 			data: {
			// 				terminalNo: this.terminalNo,
			// 				goodsId: this.goodsId,
			// 				num: num
			// 			}
			// 		})
			// 		.then(res => {
			// 			this.flag = true;
			// 			if (res.code == 200) {
			// 				this.$emit('addOrSubShoppingCart', { index: this.index, num: res.data, goodsId: this.goodsId });
			// 			} else if (res.code == 43) {
			// 				uni.showToast({
			// 					title: res.message,
			// 					icon: 'none'
			// 				});
			// 			}
			// 		})
			// 		.catch(err => {
			// 			this.flag = true;
			// 		});
			// }
		// }
	}
};
</script>

<style lang="less">
.shoppingCart-core{
	width: 690rpx;
	background: #FFFFFF;
	border-radius: 12rpx;
	margin: 30rpx;
	bottom: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	.shoppingCart-core-shopname{
		width: 630rpx;
		height: 56rpx;
		display: flex;
		align-items: center;
		margin-top: 24rpx;
		.shoppingCart-core-logo{
			width: 56rpx;
			height: 56rpx;
			margin-left: 28rpx;
		}
		.shoppingCart-core-name{
			font-size: 28rpx;
			font-family: PingFang-SC-Bold, PingFang-SC;
			font-weight: bold;
			color: #5BB954;
			margin-left: 16rpx;
		}
	}
	.shoppingCart-core-shop{
		width: 630rpx;
		height: 194rpx;
		display: flex;
		align-items: center;
	}
	.shoppingCart-core-shopsheet{
		width: 150rpx;
		height: 150rpx;
		background: rgba(255,255,255,0.21);
		border-radius: 6rpx;
		border: 1rpx solid rgba(151,151,151,0.21);
		margin-left: 28rpx;
		display: flex;
		align-items: center;
		.shoppingCart-core-logo{
			width: 150rpx;
			height: 138rpx;
		}
	}
	.shoppingCart-core-right{
		width: 376rpx;
		height: 140rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin-left: 30rpx;
		.shoppingCart-core-productname{
			font-size: 30rpx;
			font-family: PingFang-SC-Bold, PingFang-SC;
			font-weight: bold;
			color: #333333;
		}
		.shoppingCart-core-bottom{
			width: 177rpx;
			height: 56rpx;
			display: flex;
			align-items: center;
			margin-left: 199rpx;
			.shoppingCart-core-number{
				width: 56rpx;
				font-size: 26rpx;
				font-family: PingFang-SC-Bold, PingFang-SC;
				font-weight: bold;
				color: #333333;
				text-align: center;
			}
			.shoppingCart-core-img{
				width: 56rpx;
				height: 56rpx;
			}
		}
	}
}

</style>
